home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / borland / jnfb88.zip / TSORT.ZIP / FINDMATC.PRO next >
Text File  |  1987-10-20  |  5KB  |  147 lines

  1. /*******************************************************************
  2.  
  3.      Turbo Prolog Toolbox
  4.      (C) Copyright 1987 Borland International.
  5.  
  6.  (Corrections 10/87 by a.lane)
  7.  
  8.  
  9.  Returning all matching files to a file specified by backtracking.
  10.  
  11.  Ex: FindMatch("c:\\prolog\\*.PRO",SearchAttribute,MatchFileName,
  12.                 FilesAttribute,Hour,Min,Year,Month,Day, FilesSize)
  13.  
  14.  
  15.   Ex: FindMatch("c:\\*.*",63,MatchFileName,FilesAttribute,Hour,Min,
  16.                  Year,Month,Day,FilesSize)
  17.  
  18.  Range for attributes remembering it is a bitmask
  19.  Attributes     =       0       Search for ordinary files
  20.                 =       1       File is read only
  21.                 =       2       Hidden file
  22.                 =       4       System file
  23.                 =       8       Volume label
  24.                 =       16      Subdirectory
  25.                 =       32      Archive file (used by backup & restore)
  26.  
  27.  Hour           =       0-23    Hour of day when the file was created
  28.  Min            =       0-59    Minutes
  29.  Year           =       1980-2099
  30.  
  31.  Month          =       1-12
  32.  Day            =       1-31
  33.  FilesSize      =       0-30MB  Size of file
  34.  
  35. ********************************************************************/
  36.  
  37. PREDICATES
  38.   nondeterm FindMatch(String,Integer,String,Integer,Integer,Integer,
  39.                       Real,Integer,Integer,Real)
  40. /* NOTE: Last parameter in FindMatch changed from Integer to Real
  41.      10/87 a.lane
  42. */
  43.   nondeterm findfiles(STRING,INTEGER)
  44.   nondeterm findnext
  45.   convert_Match(String,String,Integer,Integer,Integer,Real,Integer,
  46.                 Integer,Real)
  47. /* NOTE: Last parameter in convert_Match changed from Integer to Real
  48.          10/87 a.lane */
  49.  
  50.   DTA_word(String,Integer,Integer)
  51.   FrontChar2(String,Char,String)
  52.   isolate_bits(Integer,Integer,Integer,Integer)
  53.   adjust( integer, real)
  54.  
  55. CLAUSES
  56.   FindMatch(FileSpec,Attribute,
  57.   FileName,FilesAttr,Hour,Min,Year,Month,Day,FilesSize):-
  58.         /* Allocate Default Disk buffer area */
  59.      str_len(DTA,128),
  60.      ptr_dword(DTA,DTA_SEG,DTA_OFF),
  61.      AX = $1A00, DS=DTA_SEG, DX=DTA_OFF,
  62.      bios($21, reg(AX,0,0,DX,0,0,DS,0),_),
  63.      findfiles(FileSpec,Attribute),
  64.      convert_Match(DTA,FileName,FilesAttr,Hour,Min,Year,Month,Day,
  65.                    FilesSize).
  66.  
  67.   findfiles(FileSpec,Attribute):-
  68.      ptr_dword(FileSpec,FSPEC_SEG,FSPEC_OFF),
  69.      bios($21, reg($4E00,0,Attribute,FSPEC_OFF,0,0,FSPEC_SEG,0),_),
  70.      findnext.
  71.  
  72.   findnext.
  73.   findnext:-
  74.         bios($21, reg($4F00,0,0,0,0,0,0,0),reg(AX,_,_,_,_,_,_,_)),
  75.         AX=0,
  76.         findnext.
  77.  
  78.  
  79.   convert_Match(DTA,FileName,FilesAttr,Hour,Min,Year,Month,Day,
  80.                 FilesSize):-
  81.         DTA_word(DTA,21,FAttr), bitand(Fattr,255,FilesAttr),
  82.         DTA_word(DTA,22,FilesTime), bitand(FilesTime,63,Min),
  83.         isolate_bits(FilesTime,6,31, Hour),
  84.         DTA_word(DTA,24,FilesDate), bitand(FilesDate,31,Day),
  85.         isolate_bits(FilesDate,5,15,Month),
  86.         isolate_bits(FilesDate,9,127,Year1),Year=Year1+1980,
  87.         DTA_word(DTA,26,LowSize),
  88.         DTA_word(DTA,28,HighSize),
  89. /* LowSize and/or HighSize may be returned as negative numbers if
  90.    they are larger than 32767 (they are, after all, integers). The
  91.    adjust() predicate turns 'em into reals for us.   a.lane
  92. */
  93.         adjust(LowSize,LS),
  94.         adjust(HighSize,HS),
  95.         FilesSize=LS+1024.0*64.0*HS,
  96.         ptr_dword(DTA,DTA_SEG,DTA_OFF),
  97.         NEW_OFF = DTA_OFF+30,
  98.         ptr_dword(FileName1,DTA_SEG,NEW_OFF),
  99.         concat(FileName1,"",FileName).  /* Create a copy */
  100.  
  101.  
  102. /*******************************************************************
  103.         Return a word from the DTA area
  104. ********************************************************************/
  105.  
  106.   DTA_word(DTA,OFF,WORD):-
  107.         ptr_dword(DTA,DTA_SEG,DTA_OFF),
  108.         NEW_OFF = DTA_OFF+OFF,
  109.         memword(DTA_SEG,NEW_OFF,WORD).
  110.  
  111.  
  112. /*******************************************************************
  113.         Special version of frontchar
  114. ********************************************************************/
  115.  
  116.   FrontChar2(S,C,S2) :- FrontChar(S,C,S2),!.
  117.   FrontChar2(S,'\000',S2) :-
  118.         ptr_dword(S,S_SEG,S_OFF),
  119.         S2_OFF=S_OFF+1,
  120.         ptr_dword(S2,S_SEG,S2_OFF).
  121.  
  122.   isolate_bits(Word,ShiftFac,BitMask,V) :-
  123.  
  124.         bitright(Word,ShiftFac,V1),
  125.         bitand(V1,BitMask,V).
  126.  
  127. /*******************************************************************
  128.  
  129.   adjust(integer, real)
  130.  
  131.         (added 10/87 by a.lane )
  132.  
  133. Recall that an integer is a 16-bit quantity.  If the high-order bit
  134. is set, the integer is  considered to be a negative number in the
  135. range -32768 to -1. To convert this value to a number from 32768 to
  136. 65535, we add  65536.0 (the '.0' part makes sure we add a real
  137. number, else we'd be effectively adding  zero!)
  138. ********************************************************************/
  139.  
  140. adjust( I, R ) :-
  141.         I < 0,
  142.         R = I + 65536.0,
  143.         !;
  144.         R = I,!.
  145.  
  146.  
  147.